﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using strange.extensions.mediation.impl;
using strange.extensions.dispatcher.eventdispatcher.api;
using System;

public class BallMediator : EventMediator {
    [Inject]
    public BallView ballview { get; set; }

    public override void OnRegister()
    {
        
        dispatcher.AddListener(Events.SCORE_CHANGE, OnUpdateScore);//监听事件处理
        ballview.dispatcher.AddListener(Events.FOR_ADD_SCORE, OnViewGetScore);
        ballview.Init();
    }
    public override void OnRemove()
    {
        dispatcher.RemoveListener(Events.SCORE_CHANGE, OnUpdateScore);
        ballview.dispatcher.RemoveListener(Events.FOR_ADD_SCORE, OnViewGetScore);
    }
    //更新分数
    private void OnUpdateScore(IEvent evt)
    {
        int score = (int)evt.data;
        ballview.UpdateScore(score);//调用方法更新UI
    }
    //增加分数
    private void OnViewGetScore()
    {
        dispatcher.Dispatch(Events.ADD_SCORE);//派发出增加分数的全局命令
    }
}
